<?php

/**
 * @author DeineAgentur UG (haftungsbeschränkt) 
 * @www http://www.deineagentur.eu/
 * @copyright 2009
 */
class MyDB_Exception extends Exception {
    public function errorMessage()
    {
    //error message
    $errorMsg = 'Error on line '.$this->getLine().' in '.$this->getFile()
    .': <b>'.$this->getMessage().'</b> is not a valid E-Mail address';
    return $errorMsg;
    }
}
 
class MyDB_ConnectionException extends MyDB_Exception {
}
 
class MyDB_QueryException extends MyDB_Exception {
}

class MyDB extends mysqli {
	private static $instance = NULL;
	
	private function __construct() {
        try {
            $data = parent::__construct( MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DB );
            if (mysqli_connect_error()) {
            	throw new MyDB_ConnectionException(mysqli_connect_error(),mysqli_connect_errno());
            }
            if (!$this->set_charset("utf8")) {
               throw new MyDB_ConnectionException('Bad Charset! - not UTF8');
            }
            throw new MyDB_ConnectionException('mysqli_connect_error(),mysqli_connect_errno()',2);
        } catch(MyDB_ConnectionException $e) { 
        }
        return $data;
	} 
	
	public static function getInstance() {
		if (self::$instance === NULL) {
			self::$instance = new self;
		}
		return self::$instance;	
	}
	
	private function __clone() {}
	
}

?>